<!--
* @Author: zhangjing
* @Date: 2025-01-07 13:09:14
* @Description: 血压记录=>
-->
<template>
	<view class="fullpage">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view class="list">
				<view class="item" v-for="(item, index) in list" :key="index">
					<view class="flex align-center justify-between">
						<view class="time">{{ item.createTime }}</view>
						<view class="state" :style="{ color: getState(item).color }">{{ getState(item).text }}</view>
					</view>
					<view class="flex align-center result u-margin-top-20">
						<view class="flex-sub">
							<view>收缩压</view>
							<view class="u-margin-top-20">
								<text class="num">{{ item.systolic_pressure }}</text>
								<text class="unit">mmHg</text>
							</view>
						</view>
						<view class="flex-sub">
							<view>舒张压</view>
							<view class="u-margin-top-20">
								<text class="num">{{ item.diastolic_pressure }}</text>
								<text class="unit">mmHg</text>
							</view>
						</view>
						<view class="flex-sub">
							<view>心率</view>
							<view class="u-margin-top-20">
								<text class="num">{{ item.hr }}</text>
								<text class="unit">次/分钟</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
import { bpSteps } from '@/utils/enum.js';
export default {
	mixins: [MescrollMixin],
	data() {
		return {
			list: []
		};
	},
	computed: {
		...mapState(['curAccount'])
	},
	created() {},
	methods: {
		getState(info) {
			if (info.systolic_pressure >= 180 || info.diastolic_pressure >= 110) {
				return bpSteps[5];
			} else if (info.systolic_pressure >= 160 || info.diastolic_pressure >= 100) {
				return bpSteps[4];
			} else if (info.systolic_pressure >= 140 || info.diastolic_pressure >= 90) {
				return bpSteps[3];
			} else if (info.systolic_pressure >= 130 || info.diastolic_pressure >= 85) {
				return bpSteps[2];
			} else if (info.systolic_pressure >= 90 || info.diastolic_pressure >= 60) {
				return bpSteps[1];
			} else if (info.systolic_pressure < 90 || info.diastolic_pressure < 60) {
				return bpSteps[0];
			}
		},
		upCallback() {
			this.getBP2Alist();
		},
		getBP2Alist() {
			let pageNum = this.mescroll.num; // 页码, 默认从1开始
			let pageSize = this.mescroll.size;
			let param = {
				pageNum: pageNum - 1,
				pageSize: pageSize
			};
			this.$postAction(this.$deviceapi.getBP2Alist, {
				detailId: this.curAccount.detailId,
				...param
			}).then(da => {
				if (this.mescroll.num == 1) this.list = []; //如果是第一页需手动制空列表
				if (da.list && da.list.length > 0) {
					let curPageData = da.list;
					this.mescroll.endBySize(curPageData.length, da.total);
					this.list = this.list.concat(curPageData); //追加新数据
				} else {
					this.mescroll.endSuccess(0, false);
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
@import 'list.scss';
</style>
